package com.ge.modules.api.controller;

import com.ge.common.utils.PageUtils;
import com.ge.common.utils.Query;
import com.ge.common.utils.R;
import com.ge.modules.api.service.TbOrderHeaderService;
import com.ge.modules.entity.TbOrderHeaderEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 订单总表
 *
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-04-26 11:48:59
 */
@RestController
@RequestMapping("/api/user/orderheader")
public class TbOrderHeaderController {
    @Autowired
    private TbOrderHeaderService orderHeaderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<TbOrderHeaderEntity> orderHeaderList = orderHeaderService.queryList(query);
        int total = orderHeaderService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(orderHeaderList, total, query.getLimit(), query.getPage());

        return R.ok().put("data", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        TbOrderHeaderEntity orderHeader = orderHeaderService.queryObject(id);

        return R.ok().put("orderHeader", orderHeader);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbOrderHeaderEntity orderHeader) {
        orderHeaderService.save(orderHeader);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TbOrderHeaderEntity orderHeader) {
        orderHeaderService.update(orderHeader);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        orderHeaderService.deleteBatch(ids);

        return R.ok();
    }

}
